home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Examples / Calc / UCalcColumns.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  7.3 KB  |  270 lines  |  [TEXT/MPS ]

  1. // UCalcColumns.h
  2. // Copyright © 1986-96 by Apple Computer, Inc. All rights reserved. 
  3.  
  4. #ifndef __UCALCCOLUMNS__
  5. #define __UCALCCOLUMNS__
  6.  
  7. //
  8. // INTERNAL INCLUDES FOR CALC
  9. //
  10.  
  11. #ifndef __UCALC__
  12. #include "UCalc.h"
  13. #endif
  14.  
  15. #ifndef __CALCUTILITIES__
  16. #include "CalcUtilities.h"
  17. #endif
  18.  
  19. class TCalcDocument;
  20. class TColumn;
  21. class TColumnsView;
  22. class TColumnList;
  23. class CColumnIterator;
  24.  
  25. //--------------------------------------------------------------------------------------------------
  26. // TColumnsView: TColumnsView is used to show the column headers, represented by the
  27. // letters A-BL. Click in this view to select an entire column or group of columns.
  28. //--------------------------------------------------------------------------------------------------
  29.  
  30. class TColumnsView : public TTextGridView
  31. {
  32.     MA_DECLARE_CLASS;
  33.     
  34. public:
  35.  
  36.     TCalcDocument* fCalcDocument;
  37.  
  38.     virtual ~TColumnsView();
  39.         // Destructor
  40.     
  41.     virtual void DoPostCreate(TDocument* itsDocument);// override 
  42.         // Create the view from a resource template
  43.  
  44.     virtual void AdornCol(short aCol, const VRect&    /*area*/);// override 
  45.         // Draw a column delimiter in the given area 
  46.  
  47.     virtual void CoordToString(short coord, CStr255& theString);
  48.  
  49.     virtual void DoMouseCommand(VPoint& theMouse,
  50.                                        TToolboxEvent*    event,
  51.                                        CPoint            /*hysteresis*/);// override 
  52.  
  53.     virtual void DoSetCursor(const VPoint&    localPoint,
  54.                                     RgnHandle        cursorRegion);// override 
  55.  
  56.     virtual void DrawCell(GridCell        aCell,
  57.                                  const VRect&    aRect);// override 
  58.  
  59.     virtual void ReSelect(RgnHandle cellRegion);
  60.  
  61. };                                                // TColumnsView 
  62.  
  63.  
  64. //--------------------------------------------------------------------------------------------------
  65. // TColumn:
  66. //--------------------------------------------------------------------------------------------------
  67.  
  68. class TColumn : public TObject
  69. {
  70.     MA_DECLARE_CLASS;
  71.     
  72. public:
  73.  
  74.     short            fNumber;
  75.     FormatRecord    fFormat;
  76.     FormatRecord    fOldFormat;                    // save original format for Undo 
  77.     short            fWidth;
  78.  
  79.     TColumn();        
  80.         // Constructor
  81.     
  82.     virtual ~TColumn();
  83.         // Destructor
  84.  
  85.     virtual void IColumn(short number);
  86.  
  87.     virtual void ReadFromDisk(TFile* aFile);
  88.  
  89.     virtual void WriteToDisk(TFile* aFile);
  90.  
  91.     virtual void ReadFromScrap(Handle    theScrap,
  92.                                       long&        scrapOffset);
  93.  
  94.     virtual void WriteToScrap(Handle    theScrap,
  95.                                      long&    scrapOffset);
  96.  
  97. };                                                // TColumn 
  98.  
  99.  
  100. //--------------------------------------------------------------------------------------------------
  101. // TColumnList:
  102. //--------------------------------------------------------------------------------------------------
  103.  
  104. class TColumnList : public TSortedList
  105. {
  106.     MA_DECLARE_CLASS;
  107.     
  108. public:
  109.     virtual ~TColumnList();
  110.         // Destructor
  111.     
  112.     virtual void IColumnList();
  113.     // Init the list procedurally 
  114.  
  115.     virtual CompareResult Compare(TObject* item1,
  116.                                          TObject* item2);// override 
  117.     // Compares columns based on columns number 
  118.  
  119.     virtual TColumn* GetColumn(ColumnNumber c);
  120.     // Returns the column whose number is c 
  121. };                                                // TColumnList 
  122.  
  123.  
  124. //--------------------------------------------------------------------------------------------------
  125. // TColumnSelector: TColumnSelector is a command object created to handle mouse movement
  126. // when you click in a TColumnsView.
  127. //--------------------------------------------------------------------------------------------------
  128.  
  129. class TColumnSelector : public TCalcSelectCommand
  130. {
  131.     MA_DECLARE_CLASS;
  132.     
  133. public:
  134.     TCalcSelectCommand* fCellSelector;            // command to handle cells view selection 
  135.  
  136.     TColumnSelector();            // override 
  137.  
  138.     virtual void IColumnSelector(TCalcDocument*    itsDocument,
  139.                                         TGridView*        itsView,
  140.                                         VPoint&            theMouse,
  141.                                         Boolean            theShiftKey,
  142.                                         Boolean            theCommandKey);
  143.     /* Create a TCalcSelectCommand to handle selection in the cells view in parallel with
  144.       selection in our view, the column headers */
  145.  
  146.     virtual ~TColumnSelector();                // override 
  147.     // Dispose of our cell selector 
  148.  
  149.     virtual void ComputeAnchorCell(GridCell& clickedCell);// override 
  150.     virtual void ComputeNewSelection(GridCell& clickedCell);// override 
  151.     virtual void DoIt();                // override 
  152.     // Perform these operations for the cells view as well as for the column headers 
  153.  
  154.     virtual TTracker* TrackMouse(TrackPhase    aTrackPhase,
  155.                                         VPoint&        /*anchorPoint*/,
  156.                                         VPoint&        /*previousPoint*/,
  157.                                         VPoint&        nextPoint,
  158.                                         Boolean        mouseDidMove);// override 
  159.  
  160. };                                                // TColumnSelector 
  161.  
  162.  
  163. //--------------------------------------------------------------------------------------------------
  164. // TColumnFormatter: TColumnFormatter is a command object created to change the style or
  165. // justification of a column. It is not undoable.
  166. //--------------------------------------------------------------------------------------------------
  167.  
  168. class TColumnFormatter : public TCommand
  169. {
  170.     MA_DECLARE_CLASS;
  171.     
  172. public:
  173.     TCalcDocument*    fCalcDocument;
  174.     RgnHandle        fSelection;                        // columns selected for formatting 
  175.  
  176.     virtual void IFormatter(TCalcDocument*    itsDocument,
  177.                                    CommandNumber    itsCommand);
  178.  
  179.     virtual ~TColumnFormatter();                // override 
  180.  
  181.     virtual void DoIt();                // override 
  182.     virtual void UndoIt();            // override 
  183.     virtual void RedoIt();            // override 
  184.  
  185. protected:
  186.     void SaveFormat(GridCell aCell);
  187.  
  188.     void SetFormat(GridCell aCell);
  189.  
  190.     void RestoreFormat(GridCell aCell);
  191.  
  192. };                                                // TColumnFormatter 
  193.  
  194.  
  195. //--------------------------------------------------------------------------------------------------
  196. // TColumnSizer: TColumnSizer is a command object created to handle mouse movement when
  197. // you click on the boundary between two columns.
  198. //--------------------------------------------------------------------------------------------------
  199.  
  200. class TColumnSizer : public TTracker
  201. {
  202.     MA_DECLARE_CLASS;
  203.     
  204. public:
  205.  
  206.     TCalcDocument*    fCalcDocument;
  207.     TCellsView*        fCellsView;
  208.     short            fLeftEdge;
  209.  
  210.     TColumn*        fColumn;
  211.     short            fNewWidth;
  212.     short            fOldWidth;                // remember previous width for Undo 
  213.  
  214.     virtual ~TColumnSizer();
  215.         // Destructor
  216.     
  217.     virtual void IColumnSizer(TCalcDocument*    itsDocument,
  218.                                      ColumnNumber    c,
  219.                                      VPoint            theMouse);
  220.  
  221.     virtual TTracker* TrackMouse(TrackPhase    /*aTrackPhase*/,
  222.                                         VPoint&        /*anchorPoint*/,
  223.                                         VPoint&        /*previousPoint*/,
  224.                                         VPoint&        nextPoint,
  225.                                         Boolean        /*mouseDidMove*/);
  226.  
  227.     virtual void TrackFeedback(TrackPhase    /*aTrackPhase*/,
  228.                                       const VPoint&    /*anchorPoint*/ ,
  229.                                       const VPoint&    /*previousPoint*/ ,
  230.                                       const VPoint&    nextPoint,
  231.                                       Boolean        mouseDidMove,
  232.                                       Boolean        /*turnItOn*/);// override 
  233.  
  234.     virtual void TrackConstrain(TrackPhase        /*aTrackPhase*/,
  235.                                        const VPoint&    /*anchorPoint*/ ,
  236.                                        const VPoint&    /*previousPoint*/ ,
  237.                                        VPoint&            nextPoint,
  238.                                        Boolean            /*mouseDidMove*/);// override 
  239.  
  240.     virtual void DoIt();                // override 
  241.  
  242.     virtual void UndoIt();            // override 
  243.  
  244.     virtual void SetColumnWidth(short newWidth);
  245.  
  246. };                                                // TColumnSizer 
  247.  
  248.  
  249. class CCalcColumnIterator : public CObjectIterator
  250. {
  251. public:
  252.     CCalcColumnIterator(TCalcDocument* theCalcDocument);
  253.  
  254.     CCalcColumnIterator(TColumnList* theColumnList);
  255.  
  256.     virtual ~CCalcColumnIterator();
  257.     
  258.     virtual TColumn* CurrentColumn();
  259.     // returns the current Column
  260.  
  261.     virtual TColumn* FirstColumn();
  262.     // return the first Column in the iteration
  263.  
  264.     virtual TColumn* NextColumn();
  265.     // advances the iteration and then returns the Column
  266. };
  267.  
  268. #endif  //UCALCCOLUMNS
  269.  
  270.